package com.xuecheng.learning.domain.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xuecheng.learning.domain.mapper.XcLearnRecordMapper;
import com.xuecheng.learning.domain.model.entity.XcCourseTables;
import com.xuecheng.learning.domain.model.entity.XcLearnRecord;
import com.xuecheng.learning.domain.model.enums.XcTablesEnum;
import com.xuecheng.learning.domain.model.vo.resp.XcTablesResp;
import com.xuecheng.learning.domain.service.XcCourseTablesService;
import com.xuecheng.learning.domain.service.XcLearnRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author itcast
 */
@Slf4j
@Service
public class XcLearnRecordServiceImpl extends ServiceImpl<XcLearnRecordMapper, XcLearnRecord> implements XcLearnRecordService {

    @Autowired
    private XcCourseTablesService xcCourseTablesService;

    @Override
    public String getLearnStatus(Long userId, Long courseId) {
        // 查询课表
        XcCourseTables xcCourseTables = xcCourseTablesService.getXcCourseTables(userId, courseId);
        if (Objects.isNull(xcCourseTables)){
            // 没有选课
            return XcTablesEnum.NO.getCode();
        }
        if (xcCourseTables.getValidtimeEnd().isBefore(LocalDateTime.now())){
            // 时间过期
            return XcTablesEnum.GUO_QI.getCode();
        }

        return XcTablesEnum.NORMAL.getCode();
    }
}
